#!/usr/bin/env python3
from hashlib import sha1
import socket
from random import random
import time
from threading import Thread
from librepeator import init_connect

rand = str( random() )

sock = socket.socket()
sock.connect( ('127.0.0.1',8001) )
print('I am ',rand)
def rv_proc():
    global sock
    print('thread')
    while True:
        try:
            r = sock.recv(1024)
            if len(r)==0:
                break
            print(r.decode() )
        except Exception as e:
            print(str(e))
            break
    print('recv end')

if init_connect(sock,'uiedd'):
    sock.settimeout(3)
    t = Thread(target=rv_proc)
    t.start()
    print('ok start send')
    c=input('\nenter leave\n')
    #rv_proc()
else:
    print('reply error: %s'%reply.decode())
sock.shutdown(socket.SHUT_RDWR)
sock.close()
print('quit')
